/*
 * ClientSocket.cpp
 *
 *  Created on: Nov 8, 2012
 *      Author: lucas
 */

#include "ClientSocket.h"
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>
#include <errno.h>
ClientSocket::ClientSocket() : CommunicationSocket() {

}

bool ClientSocket::conectar(std::string& ip, int puerto) {
	struct sockaddr_in addr;

	if (connected)
		return false;
	inet_aton(ip.c_str(), &(addr.sin_addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(puerto);
	memset(&(addr.sin_zero), 0, 8);
	if (validSocket) {
		if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1)
			return false;
	}
	else
		return false;
	connected = true;
	return true;
}

ClientSocket::~ClientSocket() {
	// TODO Auto-generated destructor stub
}

